package com.want.buss.interfaces.service.impl;

import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPOutputStream;

import javax.jws.WebService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.want.buss.interfaces.aop.OperLog;
import com.want.buss.interfaces.dto.GroupCodeParam;
import com.want.buss.interfaces.mapper181.GroupCodeMapper;
import com.want.buss.interfaces.service.IGroupCodeService;

/**
 * 防窜货系统产品数码信息
 * @author 00323357
 * @date   2019年1月15日
 */

@WebService
public class GroupCodeServiceImpl implements IGroupCodeService{
	Logger logger = Logger.getLogger(CustomerStockServiceImpl.class);  

	@Autowired
	GroupCodeMapper groupCodeMapper;
	
	@OperLog(operName = "queryGroupCode",operDesc = "查询防窜货系统产品数码信息")
	public byte[] queryGroupCode(GroupCodeParam param){
    	long startTime = System.currentTimeMillis();
		List<Map> groupCodes = groupCodeMapper.queryGroupCode(param);
    	logger.info("excTime1----"+(float)(System.currentTimeMillis()-startTime)/1000+"秒");
    	String  jsonStr = JSON.toJSONString(groupCodes);
		System.out.println("压缩前大小：" +jsonStr.getBytes().length);
    	logger.info("excTime2----"+(float)(System.currentTimeMillis()-startTime)/1000+"秒");
    	byte[]  zipJsonStr = gZip(jsonStr.getBytes());
		System.out.println("压缩后大小：" +zipJsonStr.length);
    	logger.info("excTime3----"+(float)(System.currentTimeMillis()-startTime)/1000+"秒");
    	return  zipJsonStr;
	}

	public static byte[] gZip(byte[] data) {
		byte[] b = null;
		try {
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			GZIPOutputStream gzip = new GZIPOutputStream(bos);
			gzip.write(data);
			gzip.finish();
			gzip.close();
			b = bos.toByteArray();
			bos.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return b;
	}
	
}
